﻿$(function(){
    var queryString = nehnre.queryString();
    var departmentId = queryString["departmentId"];
	var qaId = queryString["qaId"];
	if(departmentId){
	    $("#departmentId").val(departmentId);
		$(".STYLE4").wrap("<a href='../ZP/SelfExaminationView.aspx?DepartID={0}'></a>".format(departmentId));
	} else {
	    alert("条件不符合，没有部门ID!");
	    location.href="../Login.aspx";
	    return;
	}
	$("#formID").validationEngine();

	if(qaId){
		$("#qaId").val(qaId);
		loadConvenienceQa(qaId);
	}
	$.ajax({
	    url:"ashx/load_depart_by_id.ashx",
	    data:"departmentId={0}".format(departmentId),
	    success:function(data){
	        $("#departmentName").html(data);
	    }
	});
	
});

function loadConvenienceQa(qaId){
	$.ajax({
	    url:"ashx/load_convenience_qa.ashx",
	    data:"qaId={0}".format(qaId),
	    success:function(data){
	        console.log(arguments);
	        data = nehnre.parseJSON(data);
	        if(data){
	            $("#qaUrl").val(data.qaUrl);
	            $("#qaQuestion").val(data.qaQuestion);
	            $("#qaAnswer").val(data.qaAnswer);
	            if(data.lastSaveTime){
	                $("#lastSaveTime").html("最后修改：" + data.lastSaveTime);
	            } else {
	                $("#lastSaveTime").html("填写日期：" + new Date().format("yyyy-MM-dd hh:mm:ss"));
				}
	        } else {
	            alert("返回数据出错！");
	        }
	    }
	});
}

